TARGET = basic
CC = gcc
CFLAGS = -std=c99 -g -Wall -O3 -I. -Isrc
LINKER  = gcc
LDFLAGS = -Wall -I. -lm
LFLAGS  = -Wall -I. -lm

SRCDIR   = src
OBJDIR   = obj
BINDIR   = bin

SOURCES  := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS  := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) # OBJECTS = $(patsubst  %.c, %.o, $(SRCDIR))  $(addprefix $(OBJDIR)/, $(obj))
rm       = rm -f


$(BINDIR)/$(TARGET):$(OBJECTS)
	$(LINKER) $(OBJECTS) -o $@ $(LDFLAGS)
	@echo "Linking complete!"

$(OBJECTS):$(OBJDIR)/%.o:$(SRCDIR)/%.c
	$(CC) $(CFLAGS) -c $< -o $@
	@echo "Compiled "$<" successfully!"

all:$(BINDIR)/$(TARGET) create

main:$(OBJECTS)
	$(CC) $(LFLAGS) -o $(OBJECTS)

.PHONY:clean

create:
	$(shell if [ ! -d $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi)
	$(shell if [ ! -d $(SRCDIR) ]; then mkdir -p $(SRCDIR); fi)
	@echo "Create directory successfully!"

clean:
	@$(rm) $(OBJECTS)
	@echo "Cleanup complete!"

remove: clean
	@$(rm) $(BINDIR)/$(TARGET)
	@echo "Executable removed!"
